<?php 
	error_reporting(0);
	session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>首页 - 一书网</title>
	<script type="text/javascript" src="js/myfocus-2.0.1.min.js"></script><!--引入myFocus库-->
	<script type="text/javascript" src="js/mf-pattern/mF_qiyi.js"></script><!--引入风格js文件-->
	<script type="text/javascript" src="js/imagechange.js"></script>
	<link href="js/mf-pattern/mF_qiyi.css" type="text/css" /><!--引入风格css文件-->
	<link rel="stylesheet" href="style/index.css" />
</head>
<body>
	<div class="top-login">
		<div class="top-login-r clr">
			<?php 
				if($_SESSION['user_name'] === null) {
					echo "<form action='handle_login.php' method='post'>
							手机号　<input type='text' name='tel' value='' />
							密码　<input type='password' name='pwd' value='' />
							<button name='submit'>登录</button>
            　 						 没有账号？<a href='register.php' title='立即注册'> 立即注册</a>
						</form>";
				} else {
					//注销登录
					if($_GET["action"] == 'logout'){
						session_unset();
				 		echo "<p>注销登录成功！点击此处 <a href='index.php'>登录</a></p>";
					} else {
						echo "<p>欢迎 <span>{$_SESSION['user_name']}</span> 来到一书网
						 <a href='user_zone.php'>个人中心</a>｜
							<a href='index.php?action=logout'>注销</a></p>";	
					}		
				}	
			?>
    	</div>
	</div>
	<div class="wrapper clr">
		<div class="logo-search clr">
			<div class="logo">
				<img src="images/logo.png" title="欢迎来到一书网" alt="一书网" />
			</div>
			<div class="search">
				<input class="input" type="text" />
				<input class="button" type="button" value="Search"/>
			</div>
		</div>
		<div class="nav">
			<ul>
				<a href="#"><li>首　　页</li></a>
				<a href="#"><li>古典文学</li></a>
				<a href="#"><li>生活杂志</li></a>
				<a href="#"><li>艺术书籍</li></a>
				<a href="#"><li>关于我们</li></a>
			</ul>
		</div>
		<div id="title-img">
			<div class="initialize"><img src="images/titleimg3.jpg" alt="" /></div>
			<div class="pic">
				<ul>
					<li><img src="images/titleimg1.jpg" alt="" /></li>
					<li><img src="images/titleimg2.jpg" alt="" /></li>
					<li><img src="images/titleimg3.jpg" alt="" /></li>
					<li><img src="images/titleimg4.jpg" alt="" /></li>
					<li><img src="images/titleimg5.jpg" alt="" /></li>
				</ul>
			</div>
	    </div>

	    <!-- 书籍展示 开始 -->
	    <div class="book-show clr">
	    	<div class="new-book">
	    		<div class="span">
	    			<span>新书上架</span>
	    		</div>
	    		<div class="show">
	    			<ul>
    				<?php 
    					// 1、导入数据库连接文件
    					include 'link.php';
    					
    					// 2、从数据库中读出所需信息并展示
    					$sql = "select * from books order by rand() limit 8";
    					$result = mysqli_query($link, $sql);
    					
    					// 3、定位到第一条记录
    					mysqli_data_seek($result, 0);
    					
    					// 4、循环取出记录,生成展示商品信息的表格
    					if($result){
    						while ($rows = mysqli_fetch_array($result)){
    							
    							echo "<li class='book-li'>
										<div class='book-img'>
											<a href='book_detail.php?isbn={$rows['ISBN']}'>
												<img src='{$rows['img_path']}' alt='{$rows['book_name']}' />
											</a>
										</div>
										<div class='book-name'>
											{$rows['book_name']}
										</div>
										<div class='book-price'>
											<span>￥{$rows['price']}</span>
										</div>
									</li>";
    						}
    					}
    				 ?>
	    			</ul>
	    		</div>
	    	</div>
	    </div>
	</div>

	<!-- start footer -->
	<div class="footer">
		<div class="footer-content">
			<div class="link">
				<h4>友情链接</h4>
				<ul>
					<li><a href="#">Amazon</a></li>
					<li><a href="#">淘宝网</a></li>
					<li><a href="#">读书网</a></li>
					<li><a href="#">中国图书网</a></li>
				</ul>
			</div>

			<div class="about">
				<h4>关于我们</h4>
				<ul>
					<li><a href="#">关于一书</a></li>
					<li><a href="#">加入我们</a></li>
					<li><a href="#">联系方式</a></li>
					<li><a href="#">打赏一下</a></li>
				</ul>
			</div>

			<div class="copy">
				<h4>版权信息</h4>
				<p>
					Copyright &copy; ebook 2016 - 2017 <br />
					最终解释权归一书网所有
				</p>
			</div>
		</div>
	</div>
</body>
</html>